package com.example.springboot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.common.PageHelper;
import com.example.springboot.entity.RoomMark;
import com.example.springboot.mapper.RoomMarkMapper;
import com.example.springboot.service.RoomMarkService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class RoomMarkServiceImpl extends ServiceImpl<RoomMarkMapper, RoomMark> implements RoomMarkService {

    @Resource
    private RoomMarkMapper roomMarkMapper;

    @Override
    public PageInfo findAll(Integer pageNum, Integer pageSize, String search) {
        List<RoomMark> roomMarkList= roomMarkMapper.findAll(search,pageNum,pageSize);
        for(RoomMark roomMark : roomMarkList) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(roomMark.getTime() != null) roomMark.setTimestr(simpleDateFormat.format(roomMark.getTime()));
        }
       PageInfo page= PageHelper.pageHelper(roomMarkList,pageNum,pageSize);
        return page;
    }

    @Override
    public int updateroomMark(int dormroomId, String score, String text) {
        return roomMarkMapper.updateroomMark(dormroomId,score,text);
    }
}
